﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author YUga studio
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.invoicing.service;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oplink.webbase.common.persistence.Page;
import com.oplink.webbase.modules.invoicing.entity.PaidReceiveDetail;
import com.oplink.webbase.modules.invoicing.dao.PaidReceiveDetailDao;



/**
 * 告警Service
 * @author YUga studio
 * @version 2015-01-12
 */
@Component
@Transactional
public class PaidReceiveDetailService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(PaidReceiveDetailService.class);
	
	@Autowired
	private PaidReceiveDetailDao paidReceiveDetailDao;
	
	public PaidReceiveDetail get(Long id) {
		return paidReceiveDetailDao.findOne(id);
	}
	
	public Page<PaidReceiveDetail> find(Page<PaidReceiveDetail> page, PaidReceiveDetail paidReceiveDetail) {
		DetachedCriteria dc = paidReceiveDetailDao.createDetachedCriteria();
		//添加查询条件
		if (null != paidReceiveDetail.getReceiveId()
				&& StringUtils.isNotEmpty(paidReceiveDetail.getReceiveId().toString())) {
			dc.add(Restrictions.like("receiveId", "%"+paidReceiveDetail.getReceiveId()+"%"));
		}
        if (StringUtils.isNotEmpty(paidReceiveDetail.getReceiveName())){
			dc.add(Restrictions.like("receiveName", "%"+paidReceiveDetail.getReceiveName()+"%"));
		}
		if (null != paidReceiveDetail.getGoodsId()
				&& StringUtils.isNotEmpty(paidReceiveDetail.getGoodsId().toString())) {
			dc.add(Restrictions.like("goodsId", "%"+paidReceiveDetail.getGoodsId()+"%"));
		}
		if (null != paidReceiveDetail.getGoodsAmount()
				&& StringUtils.isNotEmpty(paidReceiveDetail.getGoodsAmount().toString())) {
			dc.add(Restrictions.like("goodsAmount", "%"+paidReceiveDetail.getGoodsAmount()+"%"));
		}
		dc.add(Restrictions.eq(PaidReceiveDetail.DEL_FLAG, PaidReceiveDetail.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return paidReceiveDetailDao.find(page, dc);
	}
	
	/**
	  * @function 创建查询
	  **/
	public Page<PaidReceiveDetail> getUserPaidReceiveDetail(Page<PaidReceiveDetail> page, PaidReceiveDetail paidReceiveDetail) {
		DetachedCriteria dc = paidReceiveDetailDao.createDetachedCriteria();
		//添加查询条件
		if (null != paidReceiveDetail.getReceiveId()
				&& StringUtils.isNotEmpty(paidReceiveDetail.getReceiveId().toString())) {
			dc.add(Restrictions.like("receiveId", "%"+paidReceiveDetail.getReceiveId()+"%"));
		}
        if (StringUtils.isNotEmpty(paidReceiveDetail.getReceiveName())){
			dc.add(Restrictions.like("receiveName", "%"+paidReceiveDetail.getReceiveName()+"%"));
		}
		if (null != paidReceiveDetail.getGoodsId()
				&& StringUtils.isNotEmpty(paidReceiveDetail.getGoodsId().toString())) {
			dc.add(Restrictions.like("goodsId", "%"+paidReceiveDetail.getGoodsId()+"%"));
		}
		if (null != paidReceiveDetail.getGoodsAmount()
				&& StringUtils.isNotEmpty(paidReceiveDetail.getGoodsAmount().toString())) {
			dc.add(Restrictions.like("goodsAmount", "%"+paidReceiveDetail.getGoodsAmount()+"%"));
		}
		dc.add(Restrictions.eq(PaidReceiveDetail.DEL_FLAG, PaidReceiveDetail.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return paidReceiveDetailDao.find(page, dc);
	}
	
	public PaidReceiveDetail getPaidReceiveDetail(Long id) {
		return paidReceiveDetailDao.findOne(id);
	}

	public void savePaidReceiveDetail(PaidReceiveDetail entity) {
		paidReceiveDetailDao.save(entity);
	}
	
	public void deletePaidReceiveDetail(Long id) {
		paidReceiveDetailDao.delete(id);
	}
	
	@Autowired
	public void setPaidReceiveDetailDao(PaidReceiveDetailDao paidReceiveDetailDao) {
		this.paidReceiveDetailDao = paidReceiveDetailDao;
	}	
}
